﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace BussinessLayer
{
    public class tblchidoan
    {
        DataLayer.Data odata = new DataLayer.Data();
        public DataTable SelectAllchidoan()
        {
            return odata.view_text("SELECT * FROM chidoan");
        }

        public DataTable SelectCDTheoNamHoc(string _namhoc)
        {
            return odata.view_text("select * from chidoan where namhoc = '" + _namhoc + "'");
        }

        public void insert(int _khoi, string _lop, string _namhoc)
        {
            SqlParameter[] sp = new SqlParameter[4];
            sp[0] = new SqlParameter("@khoi", _khoi);
            sp[1] = new SqlParameter("@lop", _lop);
            sp[2] = new SqlParameter("@namhoc", _namhoc);
            sp[3] = new SqlParameter("@trangthai", true);
            odata.proc_TS("tblChidoan_Insert", sp);
        }
        public void update(int _id, bool _trangthai)
        {
            SqlParameter[] sp = new SqlParameter[2];
            sp[0] = new SqlParameter("@chidoan_id", _id);
            sp[1] = new SqlParameter("@trangthai", _trangthai);
            odata.proc_TS("tblChidoan_Update", sp);
        }
        public int count(int _khoi, string _namhoc)
        {
            DataTable dt = new DataTable();
            dt = odata.view_text("SELECT chidoan_id FROM chidoan WHERE khoi='" + _khoi + "' AND namhoc='" + _namhoc +"'");
            return dt.Rows.Count;
        }
    }
}
